<template>
  <div class="goods-image" v-if="imgarr">
    <div class="large" :style="[{backgroundImage:`url(${imgarr[nowindex]})`},imgobj]" v-show="show"></div>
    <div class="middle" id="middle">
      <img :src="imgarr[nowindex]">
      <div class="layer" :style="coverobj" v-show="show"></div>
    </div>
    <ul class="small">
      <li v-for="(item,key) in imgarr" :key="key" :class="{active:nowindex==key}">
        <img :src="item" @mouseenter="nowindex=key">
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: ['imgarr'],
  data() {
    return {
      nowindex: 0,
      show: false, // 控制色块和大图显示隐藏
      coverobj: { top:'0', left: '0' },// 设置色块的位置
      imgobj: { backgroundPositionX: '0', backgroundPositionY: '0' } // 设置图像的位移
    }
  },
  mounted(){
    var obj = document.getElementById('middle')
    if(obj){
       obj.addEventListener('mousemove',(e)=>{
        console.log(e)
    }) 
    }
    
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/color.scss";
.goods-image {
  width: 480px;
  height: 400px;
  position: relative;
  display: flex;
  z-index: 500;
  .large {
    position: absolute;
    top: 0;
    left: 412px;
    width: 400px;
    height: 400px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    background-repeat: no-repeat;
    background-size: 800px 800px;
    background-color: #f8f8f8;
  }
  .middle {
    width: 400px;
    height: 400px;
    background: #f5f5f5;
    position: relative;
    cursor: move;
    .layer {
      width: 200px;
      height: 200px;
      background: rgba(0, 0, 0, 0.2);
      left: 0;
      top: 0;
      position: absolute;
    }
  }
  .small {
    width: 80px;
    li {
      width: 68px;
      height: 68px;
      margin-left: 12px;
      margin-bottom: 15px;
      cursor: pointer;
      &:hover,
      &.active {
        border: 2px solid $xtxColor;
      }
    }
  }
}
</style>